@include('admin.public.__head');
    <!-- /Navbar -->
    <!-- Main Container -->
    <div class="main-container container-fluid">
        <!-- Page Container -->
        <div class="page-container">

            <!-- Page Sidebar -->
           @include('admin.public.__left');
            <!-- /Page Sidebar -->
            <!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                        <li>
                            <i class="fa fa-home"></i>&nbsp;文章管理
                        </li>
                        <li>文章列表</li>
                    </ul>
                </div>
                <!-- /Page Breadcrumb -->
                <!-- Page Body -->
                <div class="page-body">
					<a href="{{url('admin/articleadd')}}" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i>&nbsp;添加文章</a>
					<div class="row">
						<div class="col-xs-12">
							<div class="widget">
								<div class="widget-header">
									<span class="widget-caption">添加文章</span>
									<div class="widget-buttons">
										{!!strTostr($articles->links())!!}
									</div>
								</div>
								<div class="widget-body">
									<table class="table table-hover table-bordered">
										<thead>
											<tr>
												<th>ID</th>
												<th>文章标题</th>
                                                <th>文章标签</th>
                                                <th>发布人</th>
												<th>所属导航</th>
                                                <th>是否推荐</th>
                                                <th>状态</th>
												<th>操作</th>
											</tr>
										</thead>
                                        @foreach ($articles as $v)
										<tr>
											<td>{{$v['id']}}</td>
											<td>{{$v['title']}}</td>
											<td>{{$v['tags']}}</td>
                                            <td>{{$v->members['nickname']}}</td>
                                            <td>{{$v->cates['catename']}}</td>
                                            <td>
                                            @if ($v->is_top == 1)
                                            <!-- 已推荐 -->
                                            <span class="glyphicon glyphicon-ok"></span>
                                            @else
                                            <!-- <font color="red" >未推荐</font> -->
                                            <span class="glyphicon glyphicon-remove" ></span>
                                            @endif
                                            </td>
                                            <td>
                                            @if ($v->status == 1)
                                           <!-- 上架 -->
                                           <span class="glyphicon glyphicon-ok"></span>
                                           @else
                                           <!-- <font color="red" >下架</font> -->
                                           <span class="glyphicon glyphicon-remove" ></span>
                                           @endif
                                            </td>
											<td>
                                                @if ($v->is_top == 1)
                                                <a href="#" class="btn btn-sm btn-success is_top" dataid="{{$v['id']}}" is_top="{{$v['is_top']}}"> 取消推荐</a>
                                                @else
                                                <a href="#" class="btn btn-sm btn is_top"
                                                dataid="{{$v['id']}}" is_top="{{$v['is_top']}}">
                                                文章推荐</a>
                                                @endif

                                                @if ($v->status == 1)
                                                <a href="#" class="btn btn-sm btn-primary stus" status="{{$v['status']}}" dataid="{{$v['id']}}" >
                                                下架
                                                </a>
                                                @else
                                                <a href="#" class="btn btn-sm btn-danger stus" status="{{$v['status']}}" dataid="{{$v['id']}}">
                                                上架</a>
                                                @endif
												<a href="#" class="btn btn-sm btn-warning">编辑</a>
												<a href="#" class="btn btn-sm btn-danger del" dataid="{{$v['id']}}">删除</a>
											</td>
										</tr>

                                        @endforeach
									</table>
								</div>
							</div>
						</div>
					</div>
                </div>
                <!-- /Page Body -->
            </div>
            <!-- /Page Content -->

        </div>
        <!-- /Page Container -->
        <!-- Main Container -->

    </div>

    @include('admin.public.__js');
    <script>
        $(function(){
            $('.pagination').addClass('pagination-sm');
        });

        $(".del").click(function () {
            var id = $(this).attr("dataid");
            layer.confirm("确认删除吗？",{
                icon:3,
                title:"文章删除"
            },function (index) {
                layer.close(index);
                $.ajax({
                    url:"{{url('admin/articledel')}}",
                    type:"post",
                    data:{id:id},
                    dataType:"json",
                    success:function (data) {
                        if (data.code == 1) {
                            layer.msg(data.msg,{
                                icon:6,
                                time:2000
                            },function () {
                                location.href = data.url;
                            });
                        } else {
                            layer.open({
                                title:"删除失败",
                                content:data.msg,
                                icon:5,
                                anim:6
                            });
                        }
                    }
                });
            });
            return false;
        });

        //上架下架
        $(".stus").click(function () {
            var id = $(this).attr("dataid");
            var status = $(this).attr("status");

            if (status == 1) {
                var msg = "确定下架吗？";
            } else {
                var msg = "确定上架吗？";
            }

            layer.confirm(msg,{
                icon:3,
                title:"文章操作"
            },function (index) {
                layer.close(index);
                $.ajax({
                    url:"{{url('admin/articlestus')}}",
                    type:"post",
                    data:{id:id,status:status},
                    dataType:"json",
                    success:function (data) {
                        if (data.code == 1) {
                            layer.msg(data.msg,{
                                icon:6,
                                time:2000
                            },function () {
                                location.href = data.url;
                            });
                        } else {
                            layer.open({
                                title:"操作失败",
                                content:data.msg,
                                icon:5,
                                anim:6
                            });
                        }
                    }
                });    
            });
            return false;
        });

        //推荐操作
        $(".is_top").click(function () {
            var is_top = $(this).attr("is_top");
            var id = $(this).attr("dataid");

            if (is_top == 1) {
                var msg = "确认取消推荐吗？";
            } else {
                var msg = "确认推荐吗？";
            }

            layer.confirm(msg,{
                icon:3,
                title:"推荐操作"
            },function (index) {
                layer.close(index);
                $.ajax({
                    url:"{{url('admin/articleistop')}}",
                    type:"post",
                    data:{id:id,is_top:is_top},
                    dataType:"json",
                    success:function (data) {
                        if (data.code == 1) {
                            layer.msg(data.msg,{
                                icon:6,
                                time:2000
                            },function () {
                                location.href = data.url;
                            });
                        } else {
                            layer.open({
                                icon:5,
                                title:"操作失败",
                                content:data.msg,
                                anim:6
                            });
                        }
                    }
                });
            });
            return false;
        });
    </script>
</body>
<!--  /Body -->
</html>
